Skip to content

Combat 4.2b: Stop treating vanilla Thorns as a weapon swing - #384

Merged
Travja merged 2 commits into
devfrom
combat-4.2b-thorns
Nov 18, 2026
Merged

Travja merged 2 commits into
devfrom
combat-4.2b-thorns

Conversation

@Travja

@Travja Travja commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Part of #365.

Problem

When a mob or player wearing vanilla Thorns is hit, the attacker takes damage through an EntityDamageByEntityEvent whose damager is the wearer and whose cause is THORNS. With no damage request for that event, VanillaWrapperListener.onVanillaDamage took it for a weapon swing by the wearer: the wearer's full weapon damage, crit and on-hit effects were applied to the attacker. Thorns is not a swing.

Path chosen, and why

A hit with no damage request whose cause is THORNS (every version), or whose vanilla damage type is minecraft:thorns (1.20.4+, through the existing DamageSources.get().getDamageType(e) lookup), now does break labelFullDamage right after the canFights check. That is the exact path environmental damage takes, and the path every hit takes when isFullDamage is false:

  • no damager stats are read, so no weapon damage, crit or on-hit effects
  • the damage map is the event's own damage, typed by the existing fallback: attached-damage-types, then attached-damage-causes, then the default type
  • the defender's defenses, enchant protection and everything downstream apply as for any other hit
  • the damager is not set on the DamageMeta, as for environmental damage. Bukkit's own kill credit comes from the event, so it is untouched

Nothing new was added to the pipeline. The change is one guard and a small helper. The vanilla damage type is read at most once per event and reused by the attached-damage-types fallback. It is not read for a hit with a request, and not for a hit whose cause is THORNS, where the cause already decides.

Before and after (from the tests)

Wearer's weapon: 20 physical, 100% crit chance, crit damage stat 2. Reflected Thorns hit with event damage 2.

Before After
Default install physical 60, critical, damager = wearer _vanilla_generic 2, not critical, no damager
THORNS moved to fire in attached-damage-causes physical 60 fire 2.72 against fire armor 10 (event damage 4), so defenses still apply
thorns in attached-damage-types of fire (1.20.4+) physical 60 fire 4

The shipped item_stats/damage.yml lists THORNS under attached-damage-causes of _vanilla_generic, and no damage type has attached-damage-types. A default install therefore reaches the generic type, as it already did for Thorns hits with no living damager.

Deliberately unchanged

  • Hits with a damage request: the request's origin decides, as today. Divinity's own thorns-like dealers (the Thornmail stat uses origin EFFECT) already use requests and behave exactly as before. A test pins an EFFECT-origin hit with cause THORNS: still physical 60, critical, damager = wearer.
  • User mappings win: a mapping of THORNS in attached-damage-causes, or of thorns in attached-damage-types, goes through the same lookup as before and takes precedence over the default type.
  • Unknown third-party damage stays managed by Divinity. Only Thorns changed.
  • A normal melee hit by the same wearer is still a full weapon swing (pinned by a test).
  • No Codex change, no new config keys.

Other causes that look like non-swings treated as swings (not changed)

This list is not exhaustive. It is a list for a follow-up, and nothing here changes behaviour. Read from the code, not tested. Each reaches the wrapper with a living damager (or a projectile with a living shooter) and no request, so it takes that damager's weapon stats:

  • ENTITY_EXPLOSION where the damager is a Creeper (or another living entity)
  • SONIC_BOOM (Warden)
  • MAGIC from a Guardian's beam
  • DRAGON_BREATH where the damager is the Ender Dragon
  • Any other cause a living mob uses for a special attack, such as a Ravager's roar
  • Player-thrown splash potions: cause MAGIC through the projectile branch, so the thrower's weapon stats apply
  • Wind charges
  • Player-shot fire charges

A Guardian's own thorns-style retaliation uses cause THORNS, so it is covered by this PR.

Docs

  • doc/COMBAT_RESTRUCTURE_PLAN.md: the paragraph that said Thorns is treated as a swing and "left for Phase 4" now says what 4.2b did.
  • doc/COMBAT_RESTRUCTURE_NOTES.md: one line under "Things about the code that are easy to get wrong". It has no per-item status for 4.2b, so no status line changed.

Tests

CombatCharacterizationTest. The first test was written before the change and passed on the old code (a Thorns hit carries the wearer's weapon damage and crit). After the change it was rewritten to the new expectation, so the Thorns test in the PR is a new test, not an edit of an existing one: thorns_reflectedHit_isNotAWeaponSwing_onADefaultInstall. It is one of six new tests:

  • default install (the one above)
  • vanilla damage type thorns alone, with a different cause
  • THORNS mapped in attached-damage-causes, with defenses still applied
  • thorns mapped in attached-damage-types
  • origin EFFECT request with cause THORNS: unchanged
  • ordinary melee by the same wearer: unchanged

The last two also pass with the production change removed, which shows they are unchanged.

Phase 0 characterization tests touched: none. Only the new Thorns tests were added, and the test file also gained a few helpers.

Full suite (mvn test, output to a file, real exit code 0), re-run after the lookup change and the doc edits: 190 run, 0 failures, 0 errors, 2 skipped (the two trident tests in VanillaWrapperListenerTest, as expected). That is 184 existing tests plus 6 new ones.

Break-it checks (run on the first commit, each reverted afterwards)

Break Result
Remove the Thorns check 4 Thorns tests fail (default, vanilla type alone, cause mapping, type mapping); request and melee tests still pass
Invert the check (!isThornsHit) 55 failures, 1 error across the class
Make it also catch ENTITY_ATTACK 48 failures, 1 error across the class
Drop the request == null guard the EFFECT-request test fails

The follow-up commit only moved where the damage type is read. The suite above was re-run on it and passes.

Notes

  • Breaking for the 2.0.0 set (label build:major): Thorns damage numbers change.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FaEyTt5JAkynCUVt6Z3jZK

A hit with cause THORNS (or, on 1.20.4+, vanilla damage type thorns) and no
damage request reports the Thorns wearer as its damager. The wrapper took
that for a weapon swing and applied the wearer's weapon damage, crit and
on-hit effects to the attacker. Such a hit now takes the path environmental
damage takes: the event's own damage, typed by attached-damage-types,
attached-damage-causes or the default type, reduced by the victim's defenses.

Hits that carry a damage request are unchanged: the request's origin decides.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FaEyTt5JAkynCUVt6Z3jZK
@Travja Travja added the build:major label Nov 14, 2026 — with Claude
Look the vanilla damage type up at most once per event and reuse it for the
attached-damage-types fallback. Reword the plan paragraph on Thorns and add a
note, now that 4.2b fixes it. Correct the javadoc of the new Thorns test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FaEyTt5JAkynCUVt6Z3jZK
@Travja
Travja marked this pull request as ready for review November 18, 2026 02:41
@Travja
Travja merged commit 73051a9 into dev Nov 18, 2026
2 checks passed
@Travja
Travja deleted the combat-4.2b-thorns branch November 18, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants